package com.citi.xylophone.phoneEmulator.core;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.httpclient.NameValuePair;

public class CoreExecutorUtils {
	
	public static List<NameValuePair> makeList(String uri) {

		String uriString = uri;

		uriString = uriString.replace("&amp;", "&");

		uriString = uriString.substring(uriString.indexOf("?") + 1, uriString.length());

		String[] paramString = uriString.split("&");

		List<NameValuePair> params = new ArrayList<NameValuePair>();

		for (int i = 0; i < paramString.length; i++) {

			String[] keyValue = paramString[i].split("=");
			params.add(new NameValuePair(keyValue[0], keyValue[1]));
		}

		//Add Robot Session
		params.add(new NameValuePair("botSessionID", "0-0-0-phoneEmulator-0000000000001"));
		return params;
	}
	
	
	public static NameValuePair[] getParametersFromURI(String uri) {
		
		List<NameValuePair> parameters = makeList(uri);
				
		NameValuePair params[] = new NameValuePair[parameters.size()];
		
		for (int i=0;i<parameters.size();i++){
			params[i]= parameters.get(i);
		}
		return params;
	}

}
